<template>
	<view>
		<image src="@/static/title.png" class="titleimg"></image>
		<jijie :jijieArr="jijieArr" type="jijie"></jijie>
		<view class="end" v-if="endtype">到底了，别拉了...</view>
	</view>
</template>

<script>
	import http from "@/utils/http.js";
	import jijie from '@/components/jijie/jijie.vue';

	export default {
		components: {
			jijie
		},
		data() {
			return {
				jijieArr: [],
				searchKey: "",
				endtype: false ,//false 没到底 ,true 到底了
				customData: {
					page: 1, //当前页
				},
			};
		},
		onLoad(options) {
			this.searchKey = options.searchKey
			this.getData()
		},
		onPullDownRefresh: function () {
		    console.log("下拉刷新");
		    //重新获取数据
		    this.getData();
		    //停止下拉
		    uni.stopPullDownRefresh();
		  },
		  onReachBottom: function () {
		      if (!this.endtype) {
		        this.customData.page++;
		        http.request("requirement/request/getMatchedProducts", {
		          curPagePath: "/wx/customer/classic/search.html?pageid=0piQDrywbusu9y3CXGJj",
		          keyWord: "中国",
		          pageNow: this.customData.page,
		          pageSize: 10,
		          product_type: 1
		        }, "post").then(res => {
		          const data = res.data.matchedProducts;
		          if (data.length == 0) {
					  this.endtype=true
		          } else {
		            //4.将新数据追加到原数据的后面
		            const oldData = this.jijieArr;
		            const newData = oldData.concat(data);
					this.jijieArr=newData
		          }
		        })
		      }
		    },
		methods: {
			//获取数据
			getData() {
				http.request("requirement/request/getMatchedProducts", {
					curPagePath: "/wx/customer/classic/search.html?pageid=0piQDrywbusu9y3CXGJj",
					keyWord: this.searchKey,
					pageNow: this.customData.page,
					pageSize: 10,
					product_type: 1
				}, "post").then(res => {
					this.jijieArr = res.data.matchedProducts
				})
			},
		}
	}
</script>

<style>
	.titleimg {
		width: 100%;
		height: 120rpx;
	}

	.end {
		text-align: center;
		font-weight: bold;
	}
</style>
